
function loadMenu() as ubyte
  
  dim posicion as uinteger
  dim yControl as ubyte
  border 0: ink 4: paper 0
  cls
  'wait until there is no key pressed.
  WHILE INKEY$<>"":WEND
  SetSlot3(6)
  
  printFzxAt(0,10) :   printFzxStr("0.--JUGAR") 
  printFzxAt(24,14) :   printFzxStr("1.--REDEFINE TECLAS")
  printFzxAt(48,10) :   printFzxStr("2.--TECLADO")
  printFzxAt(72,10) :   printFzxStr("3.--KEMPSTON") 
  printFzxAt(96,8)
  sinclairString = "4.--SINCLAIR"
  if sinclairPort = 0 then
      printFzxStr(sinclairString)
  else if sinclairPort = 1 then
      printFzxStr(sinclairString + " 1")
  else 
      printFzxStr(sinclairString + " 2")
  end if
    
  printFzxAt(120,10) :   printFzxStr("5.--CURSOR")
  printFzxAt(144,10) :   printFzxStr("6.--AGRADECIMIENTOS") 
  SetSlot3(0)
  
  if TipoControl = 1 then
     yControl = 6
  else if TipoControl =2 then
    yControl =9
  else if TipoControl =3 then
    yControl =12
  else if TipoControl =4 then
    yControl =15
  end if
  
  posicion = obtenerPosicionEnMapa(3, yControl)
  poke 22528+posicion, 32+128
  poke 22528+posicion+32, 32+128
  
  refreshScreen()
  'loop around until something right is pressed
  
  SetSlot3(6)
  do 
       'convert key in a number
       'play
       if MultiKeys(KEY0)
         SetSlot3(0)
         return 0
       else if MultiKeys(KEY1)
         'redifine keys
         SetSlot3(0)
         TipoControl = 1
         return 1
       else if MultiKeys(KEY2)
         'keyboard
         TipoControl = 1
         return 2
       else if MultiKeys(KEY3)
           'kempston
           TipoControl = 2
         return 3
       else if MultiKeys(KEY4)
           'sinclair
           TipoControl = 3
           return 4
        else if MultiKeys(KEY5)
           'cursor
           TipoControl = 4
           return 5
         else if MultiKeys(KEY6)
           'credits        
           return 6
       end if  
    #IFDEF SONIDO_ACTIVADO
      ejecutaSonidoAyWithoutCbank(procesa_una_nota)
    #ENDIF
    
    musicInput()
    SetSlot3(6)
  loop
  
end function
 
sub   resetVariables()
   dim estado as ubyte
   dim h as ubyte
   x =7 :y  = 15
   xp =0 : yp = 0
   statusDeliveryBurbuja = 0
   yaImp = 0
   TiempoFinalJuego   = t() + tiempo_juego 
   SetSlot3(1)       
   for h = 0 to 8
    cambiaAtributoLineaTexto(16384,h,0)
   next h
   MemCopy(OBJ_MAP_HEADER1,16384,302)
   SetSlot3(0)
   MemCopy(16384,OBJ_MAP_HEADER,302)
   sinclairPort = 0
   SetSlot3(6)
   IF statusRepAy = 1 or statusRepAy = 3 then
      SetSlot3(0)
      ejecutaSonidoAy(reproductor_en_stop)
      estado = 1
   end if
   ejecutaSonidoAy(reproductor_en_play)
end sub

sub intro()
 dim n as ubyte
 dim r as ubyte
 dim h as ubyte
 dim i as ubyte
 dim altura as ubyte
dim j as ubyte
dim textAdr as uinteger
dim textAdrWife as uinteger
dim textLength as ubyte
 
  resetVariables()
  'posicion inicial main caracter

  switch2ShadowScreenSWR()
  cargaPantalla(1)
 
  imprimeWife(20,15)
        
  paintSuitcase(26,19)
  #IFDEF SONIDO_ACTIVADO
      ejecutaSonidoAy(procesa_una_nota) 
  #ENDIF
        
  paintFishTank(3, 16)
    
  printMc(1)  
        
  saveUpperThirdOfScreen()
        
  borraContenidoDialogoTexto(16384)   
'  refreshScreen()
'  stop
  'wife first three lines
  textAdr =t_intro_wife
  /' arguments
   text address: byRef uinteger its autoincrement after it call
   firstYpositionInCar: ubyte from 0 to 23
   textLength: the length of the text been showned
   amountOfTextFragments: numberOfFragments to show
   atribute : the color of text to be showned.
  '/
  printBloqueTexto(textAdr,1,3,textLength,7)
  textAdrWife = textAdr
  'Mc first three lines
  textAdr =t_intro_mc
  printBloqueTexto(textAdr,1,3,textLength,4)
            
 'erase wife and suitcase
 eraseObjectFromScreen(20,26,15,23)
        
 'erase suitcase
 eraseObjectFromScreen(26,29,19,22)
        
 loadUpperThirdOfScreen()
        
 'drawScreenObjects()
         
 refreshScreen()
 waitKeyPressAndDepress
 'MC lines 3,4,6       
 printBloqueTexto(textAdr,1,3,textLength,4)       
 'MC lines 7,8,9
 printBloqueTexto(textAdr,1,3,textLength,4)
 
 
 borraContenidoDialogoTexto(16384)
 'MC line 10
 printBloqueTexto(textAdr,1,1,textLength,4)
' printTextoPlus(textAdr,textLength,10,1, 4)
' 
' ink 7:DibujaDialogoTexto(0)
' refreshScreen()
' waitKeyPressAndDepress
 
 ejecutaSonidoAy(reproductor_en_stop)

 'write directly to the shadow screen, given that it works with this
 'dobuleSizeTexto
 SetSlot3(7)
 ActivarBuffer()
        
  cls 
  INK 2: DoubleSizeTexto(20,110,"LA MADRUGADA",2)
  INK 2: DoubleSizeTexto(20,90,"   DESPUES",2)
  INK 2: DoubleSizeTexto(20,70,"DE LA FIESTA",2)
 DesactivarBuffer()
 SetSlot3(0)
 pause 100
 loadUpperThirdOfScreen()
        
 'erase fishTank
 eraseObjectFromScreen(3,6,16,18)  
        
 'erase MC
 eraseObjectFromScreen(7,12,15,21)
 'paint MC sleeping        
  paintMcSup(7,14)
  paintMcFoot(7,18)
  paintSleepEye(8,14)
  paintZzz(9,11)
  drawScreenObjects()
  refreshScreen()
              
  borraContenidoDialogoTexto(16384)
  FOR n=1 TO 5
      BEEP 0.18,50: BEEP 0.18,40   
      PAUSE 25
      if n = 3 then
                     eraseObjectFromScreen(9,11,11,14)
                     paintEye(7,14)
                    refreshScreen()
       end if
       BEEP 0.18,50: BEEP 0.18,40
       'ring
       printTextoPlus(textAdrWife,textLength,10,1, 7)
      
       ink 7:DibujaDialogoTexto(0)
       refreshScreen()
       PAUSE 100
                
        borraContenidoDialogoTexto(16384)
        ink 7:DibujaDialogoTexto(0)
        refreshScreen()
   NEXT n
   textAdrWife = textAdrWife + textLength+1
   'erase MC sitting , paint him standing         
    eraseObjectFromScreen(7,14,15,23)
    printMc(1)
    'who is this
    textAdr = textAdr + textLength+1
    printTextoPlus(textAdr,textLength,10,1, 4)
    textAdr = textAdr + textLength+1
    'wife good news
    printTextoPlus(textAdrWife,textLength,10,3, 7)
    textAdrWife = textAdrWife + textLength+1
    printTextoPlus(textAdrWife,textLength,10,5, 7)
    textAdrWife = textAdrWife + textLength+1
    
  
     ink 7:DibujaDialogoTexto(0)
     refreshScreen()
     waitKeyPressAndDepress      
     
     'wife returns
     
     printBloqueTexto(textAdrWife,1,3,textLength,7)
     'MCs answers       
     printBloqueTexto(textAdr,1,2,textLength,4)
     'MC thoughts      
     printBloqueTexto(textAdr,1,3,textLength,4)       
            
     alreadyPlayedIntro = 1
     ejecutaSonidoAy(reproductor_en_play)
end sub

sub credits()
dim altura as ubyte
dim n as ubyte
dim textAdr as uinteger
'ejecutaSonidoAy(reproductor_en_stop)

altura =0 

dim textLength as ubyte
    
textAdr    = t_creditos



for n =1 to 21
 
 
 SetSlot3(6)
 textLength = getTextLength(textAdr)
 WriteToTextVariable(textAdr,textLength)
 printTexto(0,altura)
   
 limpiaVariableTextMessage(textLength)
 ejecutaSonidoAy(procesa_una_nota)
 if n = 1 or n = 5 or n = 7 or  n = 9 or n = 12 or n = 16 or n = 18 then
    altura = altura +16
 else if n= 14 then
    refreshScreen()
    waitKeyPressAndDepress()
    altura = 16
    cls
 else 
        altura = altura +8
 end if
 textAdr = textAdr + textLength+1
 
next n

refreshScreen()
waitKeyPressAndDepress()



end sub


